#include "stdafx.h"
#include "setting.h"
#include "setting_op.h"
namespace aot{ namespace set{

setting_op::setting_op()
{
	this->dlg_setting_ = NULL;
	//this->dlg_setting_ = new dlg_wrapper();
	//this->dlg_setting_->Create(dlg_wrapper::IDD, CWnd::GetDesktopWindow());
}

setting_op::~setting_op()
{
	if( this->dlg_setting_ )
	{
		this->dlg_setting_->DestroyWindow();
	}
}

void setting_op::show_setting_page(int page_index /* = e_page_routine */)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
 	if( this->dlg_setting_ == NULL )
 	{
 		this->dlg_setting_ = new dlg_wrapper();
 		this->dlg_setting_->Create(dlg_wrapper::IDD, CWnd::GetDesktopWindow());
 	}
	this->dlg_setting_->refresh_display(page_index);
	if( !this->dlg_setting_->IsWindowVisible() )
	{
		int xscreen = GetSystemMetrics(SM_CXSCREEN);
		int yscreen = GetSystemMetrics(SM_CYSCREEN);
		int nHeight = 474;
		int nWidth = 636;

		CRect r;
		r.left = (xscreen - nWidth) / 2;
		r.top = (yscreen - nHeight) / 2;
		r.bottom = r.top + nHeight;
		r.right = r.left + nWidth;
		this->dlg_setting_->MoveWindow(r, TRUE);
		this->dlg_setting_->ShowWindow(SW_SHOWNORMAL);
		//::SetForegroundWindow(dlg_setting_->GetSafeHwnd());
	}
	else
	{
		this->dlg_setting_->ShowWindow(SW_SHOWNORMAL);
		::SetForegroundWindow(dlg_setting_->GetSafeHwnd());
	}
}

HWND setting_op::get_setting_dlg_hwnd()
{
	return dlg_setting_->GetSafeHwnd();
}

void setting_op::init()
{
	if( this->dlg_setting_ == NULL )
	{
		this->dlg_setting_ = new dlg_wrapper();
		this->dlg_setting_->Create(dlg_wrapper::IDD, CWnd::GetDesktopWindow());
	}
}

void setting_op::set_pdlg_null()
{
	this->dlg_setting_ = NULL;
}

void setting_op::show_dlg()
{
	if( this->dlg_setting_->GetSafeHwnd() )
	{
		this->dlg_setting_->ShowWindow(SW_SHOW);
	}
}

void setting_op::hide_dlg()
{
	if( this->dlg_setting_->GetSafeHwnd() )
	{
		this->dlg_setting_->ShowWindow(SW_HIDE);

	}
}

}}